package com.example.monitor.repository;

import com.example.monitor.model.DO.SystemSetting;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface SystemSettingsRepository extends JpaRepository<SystemSetting, Integer> {

    // 根据key查询单个设置项
    Optional<SystemSetting> findByKey(String key);

    // 批量查询设置项
    @Query("SELECT s FROM SystemSetting s WHERE s.key IN :keys")
    List<SystemSetting> findByKeys(@Param("keys") List<String> keys);

    // 更新设置值
    @Modifying
    @Query("UPDATE SystemSetting s SET s.value = :value WHERE s.key = :key")
    int updateValueByKey(@Param("key") String key, @Param("value") String value);
}